<?php

/**
 * Comment form.
 *
 * @package    lezgro
 * @subpackage form
 * @author     Your name here
 * @version    SVN: $Id: sfDoctrineFormTemplate.php 23810 2009-11-12 11:07:44Z Kris.Wallsmith $
 */
class CommentForm extends BaseCommentForm
{
  public function configure()
  {
      $this->setWidgets(array(
      'user_profile_id' => new sfWidgetFormInputHidden(),
          'user_name'=>new sfWidgetFormInput(),
      'text'            => new sfWidgetFormTextarea(),
          'email'=>new sfWidgetFormInput(),
      'article_id'   => new sfWidgetFormInputHidden(),
    ));

    $this->setValidators(array(
      'user_profile_id' => new sfValidatorDoctrineChoice(array('model' => $this->getRelatedModelName('UserProfile'), 'required' => false)),
        'user_name'=>new sfValidatorString(array('required'=>true)),
      'text'            => new sfValidatorString(array('required'=>true)),
        'email'=>new sfValidatorEmail(array('required'=>true),array()),
      'article_id'   => new sfValidatorDoctrineChoice(array('multiple' => false, 'model' => 'Article', 'required' => true),array('required'=>'Email required')),
    ));
    
    $this->widgetSchema->setNameFormat('comment[%s]');

    $this->errorSchema = new sfValidatorErrorSchema($this->validatorSchema);

    $this->setupInheritance();
  }
  public function bind(array $taintedValues = null, array $taintedFiles = null) {
      if(sfContext::getInstance()->getUser()->getGuardUser())
       $taintedValues['user_profile_id']=sfContext::getInstance()->getUser()->getUserProfile()->getId();
        return parent::bind($taintedValues, $taintedFiles);
    }
}
